package iscript.uiFramework.components.container
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.TimerEvent;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	import flash.utils.Timer;
	import iscript.uiFramework.components.layout.AbsoluteLayout;
	import iscript.uiFramework.components.layout.FlowLayout;
	import iscript.uiFramework.components.layout.ILayoutManager;
	import iscript.uiFramework.components.layout.LayoutMargin;
	import iscript.uiFramework.components.panel.ScrollPanel;
	import iscript.uiFramework.components.UIComponent;
	
	public class ScrollBox extends Container implements IBox
	{
		
		private var _container:Container;
		private var _scrollPanel:ScrollPanel;
		private var _timerId:uint;
		
		
		public function ScrollBox(preferWidth:Number = 100, preferHeight:Number = 100)
		{
			super(preferWidth,preferHeight);
		}
		
		override protected function initialize():void
		{
			_scrollPanel = new ScrollPanel();
			_scrollPanel.width = _preferWidth;
			_scrollPanel.height = _preferHeight;
			
			_container = new Container(_preferWidth, _preferHeight);
			_container.getLayout().margin = LayoutMargin.Empty;
			_scrollPanel.source = _container;
			_scrollPanel.render(this);
			_container.render(this);
			
			super.initialize();
		}
		
		override public function set width(value:Number):void
		{
			_scrollPanel.width = value;
			_container.width = value;
			sourceUpdate();
			super.width = value;
		}
		
		override public function get width():Number
		{
			return _preferWidth
			//return super.width;
		}
		
		override public function get height():Number
		{
			return _preferHeight
			//return super.width;
		}
		
		override public function set height(value:Number):void
		{
			_scrollPanel.height = value;
			_container.width = value;
			sourceUpdate();
			super.height = value;
		}
		
		/**
		 * 允许内容拖动
		 */
		public function get scrollDrag():Boolean
		{
			return _scrollPanel.scrollDrag;
		}
		
		/**
		 * 允许内容拖动
		 */
		public function set scrollDrag(value:Boolean):void
		{
			_scrollPanel.scrollDrag = value;
		}
		
		public function set processWidth(value:Number):void
		{
			_scrollPanel.processWidth = value;
		}
		
		public function get processWidth():Number
		{
			return _scrollPanel.processWidth
		}
		
		public function set processHeight(value:Number):void
		{
			_scrollPanel.processHeight = value;
		}
		
		public function get processHeight():Number
		{
			return _scrollPanel.processHeight
		}
		
 
		
		override public function get container():DisplayObjectContainer
		{
			return _container;
		}
		
		override public function setLayout(layout:ILayoutManager):void
		{
			_container.setLayout(layout);
		}
		
		override public function getLayout():ILayoutManager
		{
			return _container.getLayout();
		}
		
		override public function append(target:DisplayObject):void
		{
			_container.getLayout().append(target);
			sourceUpdate();
		}
		
		override public function remove(target:DisplayObject):void
		{
			_container.getLayout().remove(target);
			sourceUpdate();
		}
		
		/**
		 * 更新内容源
		 */
		override public function sourceUpdate():void
		{
			 _container.getLayout().updateAlign();
			 _scrollPanel.sourceUpdate();
		}
		
/*		public function full():void
		{
		}*/
		
				
		override public function clear():void {			
			_container.getLayout().clear();
			processWidth = 0;
			processHeight = 0;
			sourceUpdate()
			}
		
		override public function render(container:DisplayObjectContainer = null):void
		{
			background = true;
			getBackground().begFillColor(0xFFFFFF)
			super.render(container);
		}
		
		
		
		public function get VSilderPolicy():String
		{
			return _scrollPanel.VSilderPolicy;
		}
		
		public function set VSilderPolicy(value:String):void
		{
			  _scrollPanel.VSilderPolicy = value;
		
		}
		
		public function get HSilderPolicy():String
		{
			return _scrollPanel.HSilderPolicy;
		}
		
		public function set HSilderPolicy(value:String):void
		{
			 _scrollPanel.HSilderPolicy = value;
		}
	}

}